package neusoft.edu.cn.a215lmeordering.model;

import android.view.View;
import android.widget.Toast;

import neusoft.edu.cn.a215lmeordering.Listener.Listener;
import neusoft.edu.cn.a215lmeordering.bean.CollectFood;
import neusoft.edu.cn.a215lmeordering.bean.CollectShop;
import neusoft.edu.cn.a215lmeordering.service.AllService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class CollectionShopModel {

    private Retrofit retrofit;
    private View view;

    public CollectionShopModel(View view){
        this.view=view;
        retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(int user_id ,int shop_id ){

        AllService Service = retrofit.create(AllService.class);

        Call<CollectShop> Call = Service.getUserCollectionShop(user_id,shop_id);

        Call.enqueue(new Callback<CollectShop>() {
            @Override
            public void onResponse(Call<CollectShop> call, Response<CollectShop> response) {
                if(response.body().getSuccess().equals("1")){
                    Toast.makeText(view.getContext(),"操作成功",Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(view.getContext(),"操作失败",Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(Call<CollectShop> call, Throwable t) {
                t.toString();
            }
        });

    }
}
